﻿using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;

namespace MiniFox.Infrastructure
{
    /// <summary>
    /// 
    /// </summary>
    public class TreeResultObject : TreeResultObject<IDictionary<string, object>>
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="flatData"></param>
        /// <param name="nodeKey"></param>
        /// <param name="superKey"></param>
        /// <param name="sortKey"></param>
        /// <param name="groupKey"></param>
        public TreeResultObject(IEnumerable<IDictionary<string, object>> flatData, string nodeKey, string superKey, string sortKey, string groupKey)
           : base(flatData, nodeKey, superKey, sortKey, groupKey)
        {
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected override IEnumerable<IGrouping<object, IDictionary<string, object>>> GetGroups()
        {
            var groups = FlatData.GroupBy(d => d[this.GroupKey]);
            return groups;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="groupId"></param>
        /// <param name="groupFlatData"></param>
        /// <returns></returns>
        protected override ITreeGroup CreateTreeGroup(object groupId, IEnumerable<IDictionary<string, object>> groupFlatData)
        {
            return new TreeGroup(groupId, this.NodeKey, this.SuperKey, this.SortKey, groupFlatData);
        }
    }

}
